<?php
/**
*
*	后台公告设置 @zairwolf
*/
if(!defined('IN_ACP')) exit('Access Denied');

if(!$action) {
	if(in_array($pfile, array('annouce_add'))) $action='add';
}


//公告更新
if($action=='update') {
	$id=_post('id');
	$title=_post('title');
	$content=_post('content');
	if(!$id || !$title || !$content) b('内容不全');
	db_q("update rd8_announce set title='$title',content='$content',dateline='".TIMESTAMP."' where id='$id'");
	clearCache('cache');
	j("?ptype=$ptype&pfile=$pfile", '更新成功');
}

//公告添加
if($action=='insert') {
	$title=_post('title');
	$content=_post('content');
	if(!$title || !$content) b('内容不全');
	db_q("insert into rd8_announce set title='$title',content='$content',dateline='".TIMESTAMP."'");
	clearCache('cache');
	j("?ptype=$ptype&pfile=$pfile", '添加成功');
}

//公告添加
if($action=='add') {
	$tpl = new T($ptype.'_'.$pfile);
	$tpl->output();
}

//公告修改
if($action=='edit') {
	$id=_get('id');
	$row=db_r("select * from rd8_announce where id='$id'");
	if(!$row) b('不存在此公告');

	$tpl = new T($ptype.'_'.$pfile.'_'.$action);
	$tpl->assign(html_show($row,false));
	$tpl->output();
}


//删除公告
if($action=='delete') {
	$id=_get('id');
	db_q("delete from rd8_announce where id='$id'");
	clearCache('cache');
	//日志记录
	j("?ptype=$ptype&pfile=$pfile", '删除成功');
}

//用户列表
if(!$action){
	$total=db_r("select count(*) as totalnum from rd8_announce");
	$pagelink=page($total['totalnum'],20,0,0);
	$list=db_rows("select * from rd8_announce order by dateline desc $pagelink[limit]");

	$tpl = new T($ptype.'_'.$pfile);
	$tpl->assign(array(
		'list'   => html_show($list),
		'pagelink' => $pagelink['output'],
	));
	$tpl->output();
}

